"use client"; /** * /w/:workspace/settings/automations/new — CREATE flow. * * A small form (name + optional description) that creates a DRAFT automation * (POST /workspaces/:id/automations) then navigates to the editor. The editor * (…/automations/:id) is where triggers/conditions/actions are configured. */ import { useState } from "react"; import { useParams, useRouter } from "next/navigation"; import { useMutation } from "@tanstack/react-query"; import { ArrowLeft, Loader2, Plus } from "lucide-react"; import { toast } from "@/stores/ui-store"; import { apiFetch } from "@/lib/api"; import { useWorkspace } from "@/hooks/use-workspace"; import { SettingsShell, Section, Field, inputCls } from "@/components/settings/settings-shell"; import type { AutomationDetail } from "@/components/automations/lib"; export default function NewAutomationPage() { const params = useParams<{ workspace: string }>(); const slugOrId = params?.workspace ?? ""; const router = useRouter(); const { data: ws, isLoading } = useWorkspace(slugOrId); const wid = ws?.id ?? ""; const [name, setName] = useState(""); const [description, setDescription] = useState(""); const create = useMutation({ mutationFn: (input: { name: string; description?: string }) => apiFetch(`/workspaces/${wid}/automations`, { method: "POST", body: { name: input.name, ...(input.description ? { description: input.description } : {}) } }), onSuccess: (res) => { toast("success", "Automation created", "Add triggers and actions to make it run."); router.push(`/w/${slugOrId}/settings/automations/${res.id}`); }, onError: (err) => { toast("error", "Could not create automation", err instanceof Error ? err.message : undefined); } }); return ( {isLoading || !ws ? (

Loading…

) : (
setName(e.target.value)} maxLength={100} />